/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package task;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import java.util.LinkedList;
import java.util.List;
import javafx.scene.chart.XYChart;

/**
 *
 * @author Dima
 */
public class Utils {

    public static List<XYChart.Data<Double, Double>> readCSVFile(File file) throws Exception {
        List<XYChart.Data<Double, Double>> result = new LinkedList<>();
        
        try (BufferedReader br = new BufferedReader(new FileReader(file))) {
            String line;
            while ((line = br.readLine()) != null) {
                String[] tokens = line.split(";");
                
                if (tokens.length != 2) {
                    throw new Exception("Wrong CSV file format");
                }
                
                XYChart.Data<Double, Double> item = new XYChart.Data<>(Double.parseDouble(tokens[0]), Double.parseDouble(tokens[0]));
                result.add(item);
            }
        }
        
        return result;
    }
}
